public class test02 {
    public List<Integer> findAnagrams(String s, String p) {
        //数组哈希表+滑动窗口
        int[] need = new int[128];
        int[] window = new int[128];
        for(int i = 0;i<p.length();i++){
            need[p.charAt(i)]++;
        }
        List<Integer> list = new ArrayList<>();
        int left = 0,right = 0;
        while(right<s.length()){
            char ch = s.charAt(right);
            window[ch]++;
            while(window[ch]>need[ch]){
                char rem = s.charAt(left);
                window[rem]--;
                left++;
            }
            if(right-left+1==p.length()){
                list.add(left);
            }
            right++;
        }
        return list;
    }
}
